import os;
filename="blank.txt"
_rename_filename="rename_blank"
mode="w+"
#Opens a file for both writing and reading. Overwrites the existing file if the file exists. 
#If the file does not exist, creates a new file for reading and writing.
_file_object=open(filename,mode)
_file_object.write("file,operation")
_file_object.seek(0,0)
#after write,position is at the end.
print(_file_object.tell());
print(_file_object.read(4))
print(_file_object.tell())
_file_object.seek(6)
print(_file_object.tell())
_file_object.close()
#before rename or delete,remember to close the file object,otherwise os will detect this process is dealing with the file 
if not os.path.isfile(_rename_filename):
	os.rename(filename,_rename_filename);
#os.rename("rename_blank.py2","blank.txt");
mode="r+";
try:
	_file_object=open(filename,mode);
except IOError,Argument:
	print "no such file",Argument
else:
	print "success"
finally:
	_file_object.close()
	
print os.path.isfile(filename)